// 计算小数点精度
export const accuracy = (num1, num2) => {
	//将数字转换成字符串
	num1 = num1.toString()
	num2 = num2.toString()
	//获取小数点的位置
	const index1 = num1.indexOf('.')
	const index2 = num2.indexOf('.')
	//如果小数点存在，那么就再获取各自的小数位数
	let ws1 = 0
	let ws2 = 0
	if (index1 != -1) ws1 = num1.split('.')[1].length
	if (index2 != -1) ws2 = num2.split('.')[1].length
	//看谁的小数位数大，谁的小数位数小
	const bigger = ws1 > ws2 ? ws1 : ws2
	const smaller = ws1 < ws2 ? ws1 : ws2
	//计算得到需要补齐的 0的个数
	const zerosCount = bigger - smaller
	//好了，现在开始不管三七二十一,全部去除小数点
	num1 = num1.replace('.', '')
	num2 = num2.replace('.', '')
	//比较 num1和 num2谁大,比较方法就是看谁是 smaller,是 smaller 的一方就补0
	for (let i = 0; i < zerosCount; i++) {
		ws1 == smaller ? (num1 += '0') : (num2 += '0')
	}
	//开始计算
	let sum = parseInt(num1) + parseInt(num2)
	//根据较大的小数位数计算倍数
	let beishu = 1
	for (let i = 0; i < bigger; i++) {
		beishu = beishu * 10
	}
	sum = sum / beishu
	return sum
}
